home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-07-03 | 2.8 KB | 70 lines | [TEXT/R*ch] |
- (* StringCvt -- SML Standard Library *)
-
- datatype radix = BIN | OCT | DEC | HEX;
-
- datatype realfmt =
- SCI of int option (* scientific, arg = # dec. digits, dflt=6 *)
- | FIX of int option (* fixed-point, arg = # dec. digits, dflt=6 *)
- | GEN of int option (* auto choice of the above, *)
- (* arg = # significant digits, dflt=12 *)
-
- type 'charsrc accessor = {getc : 'charsrc -> (char * 'charsrc) option}
- type ('charsrc, 'result) converter =
- 'charsrc accessor -> 'charsrc -> ('result * 'charsrc) option
-
- val skipWS : 'charsrc accessor -> 'charsrc -> 'charsrc
- val scanString : (int, 'result) converter -> string -> 'result option
-
- val toChar : string -> char option (* ML escape sequences *)
- val toString : string -> string option (* ML escape sequences *)
-
- val fromChar : char -> string (* ML escape sequences *)
- val fromString : string -> string (* ML escape sequences *)
-
- val padLeft : char -> int -> string -> string
- val padRight : char -> int -> string -> string
-
-
- (* These datatypes and functions are used for scanning strings into
- data values, and for formatting data values to strings.
-
- A character source charsrc can be used to obtain a sequence of
- characters; it can be thought of as a functional character stream.
-
- A 'charsrc accessor getc obtains characters from a 'charsrc, one at
- a time.
-
- A character source scanner takes a 'charsrc accessor getc as
- argument and uses it to scan some simple data value from the
- character source.
-
- [skipWS getc charsrc] returns a character source which is charsrc
- less any leading whitespace.
-
- [scanString scan s] turns the string s into a character source and
- applies the scanner `scan' to that source.
-
- [toChar s] scans the string s for an ML character or escape
- sequence into the character it represents. Does not skip leading
- whitespace. For instance, toChar "\\065" equals #"A"
-
- [fromChar c] returns a string consisting of the character c, or an
- ML escape sequence corresponding to c. For instance,
- fromChar #"A" equals "\\065"
-
- [toString s] scans the string s as an ML source program string,
- converting escape sequences into the appropriate characters. Does
- not skip leading whitespace.
-
- [fromString s] returns a string corresponding to s, with
- non-printable characters replaced by escape sequences.
-
- [padLeft c n s] returns the string s if size s >= n, otherwise pads
- s with (n - size s) copies of the character c on the left.
- In other words, right-justifies s in a field n characters wide.
-
- [padRight c n s] returns the string s if size s >= n, otherwise pads
- s with (n - size s) copies of the character c on the right.
- In other words, left-justifies s in a field n characters wide.
- *)
-